<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="公众号登录账号" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入公众号登录账号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="营业执照注册号" prop="businessNumber">
        <el-input
          v-model="queryParams.businessNumber"
          placeholder="请输入营业执照注册号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人姓名" prop="legalPersonName">
        <el-input
          v-model="queryParams.legalPersonName"
          placeholder="请输入法人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人身份证号" prop="legalPersonIdCard">
        <el-input
          v-model="queryParams.legalPersonIdCard"
          placeholder="请输入法人身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="管理员姓名" prop="systemName">
        <el-input
          v-model="queryParams.systemName"
          placeholder="请输入管理员姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="管理员手机号" prop="systemPhone">
        <el-input
          v-model="queryParams.systemPhone"
          placeholder="请输入管理员手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['media:createWechatMp:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
        <el-col :span="1.5">
          <el-button
            type="primary"
            size="mini"
            @click="handCreateMp"
            v-hasPermi="['media:createWechatMp:add']"
          >一键登录</el-button>
        </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          size="mini"
          @click="getPhoneCacheCode"
          v-hasPermi="['media:createWechatMp:add']"
        >获取验证码</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          size="mini"-->
<!--          @click="handBatchSubmit"-->
<!--          v-hasPermi="['media:createWechatMp:add']"-->
<!--        >资料提交</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          size="mini"
          @click="handBatchCreate"
          v-hasPermi="['media:createWechatMp:add']"
        >一键创建</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['media:createWechatMp:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['media:createWechatMp:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['tiktokCover:tiktokCover:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['media:createWechatMp:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <div style="font-size: 13px;color: #ea6161;margin-top: 10px;margin-bottom: 10px">
      绿色为已登录的账号，红色为未登录账号，如点击一键登录后还未登录说明账号或密码错误！
    </div>

    <el-table v-loading="loading" :data="createWechatMpList" :row-class-name="rowStyle" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键" align="center" prop="id" v-if="true"/>-->
<!--      <el-table-column label="部门id" align="center" prop="deptId" />-->
<!--      <el-table-column label="用户id" align="center" prop="userId" />-->
      <el-table-column label="公众号登录账号" align="center" prop="username" />
      <el-table-column label="公众号登录密码" align="center" prop="password" />
      <el-table-column label="账号类型" align="center" prop="accountType">
              <template slot-scope="scope">
                {{ scope.row.accountType === 1 ? '订阅号' : '服务号' }}
              </template>
            </el-table-column>
      <!-- <el-table-column label="主体类型 " align="center" prop="enterpriseType" /> -->
      <el-table-column label="营业执照注册号" align="center" prop="businessNumber" />
      <el-table-column label="企业名称" align="center" prop="businessName" />
      <el-table-column label="法人姓名" align="center" prop="legalPersonName" />
      <el-table-column label="法人扫码" align="center" prop="legalPersonScanStatus">
        <template slot-scope="scope">
          <el-button v-if="scope.row.legalPersonScanStatus === 0" size="mini" type="primary" @click="legalPersonScan(scope.row)">法人扫码</el-button>
          <el-tag v-else-if="scope.row.legalPersonScanStatus === 1" type="success">扫码成功</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="管理员扫码" align="center" prop="systemScanStatus">
        <template slot-scope="scope">
          <el-button v-if="scope.row.systemScanStatus === 0" size="mini" type="primary" @click="systemScan(scope.row)">管理员扫码</el-button>
          <el-tag v-else-if="scope.row.systemScanStatus === 1" type="success">扫码成功</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="管理员验证码" width="120" align="center" prop="systemPhoneCaptcha">
        <template slot-scope="scope">
          <el-button v-if="!scope.row.systemPhoneCaptcha"
                     :id="'phoneCaptcha' + scope.row.id"
                     size="mini"
                     type="primary"
                     @click="sendPhoneCacheOne(scope.row)">发送验证码</el-button>
          <el-tag v-else-if="scope.row.systemPhoneCaptcha" type="success">已填验证码<br>({{scope.row.systemPhoneCaptcha}})</el-tag>
        </template>
      </el-table-column>
<!--      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="法人身份证号" align="center" prop="legalPersonIdCard" />
      <el-table-column label="管理员姓名" align="center" prop="systemName" />

      <el-table-column label="管理员身份证号" align="center" prop="systemIdCard" />
      <el-table-column label="管理员手机号" align="center" prop="systemPhone" />
      <el-table-column label="返回结果" align="center" prop="registerRes" />
      <!-- <el-table-column label="是否注册成功" align="center">
              <template slot-scope="scope">
                <el-tag :type="scope.row.isSuccess === 0 ? 'danger' : 'success'">{{ scope.row.isSuccess === 0 ? '未成功' : '已成功' }}</el-tag>
              </template>
            </el-table-column>   -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['media:createWechatMp:edit']"
          >修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


<!--    法人扫码-->
    <el-dialog title="法人扫码" width="400px"  :visible.sync="showLegalPersonQRVisible" @close="closeModel">
      <div style="font-size: 15px;color: #1f2d3d;margin-bottom: 20px">
        请核对信息后扫码<br><br>
        企业名称:{{checkData.businessName}}<br>
        法人姓名:{{checkData.legalPersonName}}<br>
        法人身份证号:{{checkData.legalPersonIdCard}}<br>
      </div>
      <div v-if="!legalPersonImg" v-loading="!legalPersonImg" style="height: 200px"></div>
      <div v-else style="text-align: center;margin-bottom: 30px">
        <img :src="legalPersonImg" alt="">
      </div>
    </el-dialog>

<!--管理员扫码-->
    <el-dialog title="管理员扫码" width="500px" :visible.sync="systemScanVisible" @close="closeModel">
      <div style="font-size: 15px;color: #7c7c7c;margin-bottom: 10px">
        请核对信息后发送验证码获取二维码<br><br>
        管理员姓名:{{checkData.systemName}}<br><br>
        管理员身份证号:{{checkData.systemIdCard}}<br><br>
        管理员手机号:{{checkData.systemPhone}}
      </div>
        <div v-if="!systemQRCodeImg" v-loading="!systemQRCodeImg" style="height: 200px"></div>
        <div v-else style="text-align: center;margin-bottom: 30px">
          <img :src="systemQRCodeImg" alt="">
        </div>
    </el-dialog>

<!--  管理员验证码 -->
    <el-dialog title="管理员验证码" width="500px" :visible.sync="systemPhoneCacheVisble" @close="closeModel">
      <div style="font-size: 15px;color: #7c7c7c;margin-bottom: 10px">
        请核对管理员手机号<br><br>
        管理员手机号:{{checkData.systemPhone}}
        <el-button size="mini" style="margin-left: 30px" type="primary" :disabled="disableSendButton" @click="sendPhoneCache">{{ disableSendButton ? '已发送' : '发送验证码' }}</el-button>

        <div style="margin-top: 30px">
          <el-form ref="form"   label-width="80px">
            <el-form-item label="验证码" prop="username">
              <el-input v-model="form.systemPhoneCaptcha" style="width: 180px;" placeholder="请输入手机验证码" />
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div style="text-align: center">
        <el-button   type="primary"  @click="submitFormSystemPhoneCaptcha">确 定</el-button>
      </div>
    </el-dialog>


<!--    文件上传 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <!--          <div class="el-upload__tip" slot="tip">-->
          <!--            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据-->
          <!--          </div>-->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 添加或修改快速创建公众号对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公众号登录账号" prop="username">
          <el-input v-model="form.username" placeholder="请输入公众号登录账号" />
        </el-form-item>
        <el-form-item label="公众号登录密码" prop="password">
          <el-input v-model="form.password" placeholder="请输入公众号登录密码" />
        </el-form-item>
        <el-form-item label="账号类型" prop="accountType">
          <el-select v-model="form.accountType" placeholder="请选择账号类型">
            <el-option label="订阅号" value="1"></el-option>
            <el-option label="服务号" value="2"></el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="主体类型" prop="enterpriseType">-->
<!--          <el-input v-model="form.enterpriseType" placeholder="请输入主体类型" />-->
<!--        </el-form-item>-->
        <el-form-item label="企业名称" prop="businessName">
          <el-input v-model="form.businessName" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="营业执照注册号" prop="businessNumber">
          <el-input v-model="form.businessNumber" placeholder="请输入营业执照注册号" />
        </el-form-item>
        <el-form-item label="法人姓名" prop="legalPersonName">
          <el-input v-model="form.legalPersonName" placeholder="请输入法人姓名" />
        </el-form-item>

        <el-form-item label="法人身份证号" prop="legalPersonIdCard">
          <el-input v-model="form.legalPersonIdCard" placeholder="请输入法人身份证号" />
        </el-form-item>
        <el-form-item label="管理员姓名" prop="systemName">
          <el-input v-model="form.systemName" placeholder="请输入管理员姓名" />
        </el-form-item>
        <el-form-item label="管理员身份证号" prop="systemIdCard">
          <el-input v-model="form.systemIdCard" placeholder="请输入管理员身份证号" />
        </el-form-item>
        <el-form-item label="管理员手机号" prop="systemPhone">
          <el-input v-model="form.systemPhone" placeholder="请输入管理员手机号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCreateWechatMp, getCreateWechatMp, delCreateWechatMp, addCreateWechatMp, updateCreateWechatMp, createMp,getQRCodeImage,
  batchCreateMp,batchCreateSubmit,getPhoneCacheCodeApi,getQRCodeRes, getSystemPhoneCache } from "@/api/media/createWechatMp";
import {Message} from "element-ui";
import { getToken } from "@/utils/auth";
export default {
  name: "CreateWechatMp",
  data() {
    return {
      //法人二维码
      legalPersonImg:'',
      systemQRCodeImg : '',
      disabledRow: [],
      buttonClicked:false,
      disableSendButton: false,
      systemScanVisble:false,
      systemPhoneCacheVisble:false,
      ticket:'',
      systemScanImg:'',
      checkData:{},
      showLegalPersonQRVisible:false,
      systemScanVisible:false,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      scanTime:300, //扫码时间默认5分钟
      // 快速创建公众号表格数据
      createWechatMpList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/media/createWechatMp/importData"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: undefined,
        userId: undefined,
        username: undefined,
        password: undefined,
        accountType: undefined,
        enterpriseType: undefined,
        businessNumber: undefined,
        legalPersonName: undefined,
        legalPersonIdCard: undefined,
        systemName: undefined,
        systemIdCard: undefined,
        systemPhone: undefined,
        systemPhoneCaptcha: undefined,
        isSuccess: undefined,
        businessName:undefined,
        legalPersonScanStatus:undefined,
        systemScanStatus:undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "主键不能为空", trigger: "blur" }
        ],
        username: [
          { required: true, message: "公众号登录账号不能为空", trigger: "blur" }
        ],
        password: [
          { required: true, message: "公众号登录密码不能为空", trigger: "blur" }
        ],
        // businessName: [
        //   { required: true, message: "企业名称不能为空", trigger: "blur" }
        // ],
        accountType: [
          { required: true, message: "账号类型：1、订阅号、2、服务号不能为空", trigger: "change" }
        ],
        // businessNumber: [
        //   { required: true, message: "营业执照注册号不能为空", trigger: "blur" }
        // ],
        // legalPersonName: [
        //   { required: true, message: "法人姓名不能为空", trigger: "blur" }
        // ],
        // legalPersonIdCard: [
        //   { required: true, message: "法人身份证号不能为空", trigger: "blur" }
        // ],
        // systemName: [
        //   { required: true, message: "管理员姓名不能为空", trigger: "blur" }
        // ],
        // systemIdCard: [
        //   { required: true, message: "管理员身份证号不能为空", trigger: "blur" }
        // ],
        // systemPhone: [
        //   { required: true, message: "管理员手机号不能为空", trigger: "blur" }
        // ],
        // isSuccess: [
        //   { required: true, message: "是否注册成功不能为空", trigger: "blur" }
        // ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {

    /**
     * 法人扫码
     * @param row
     */
    async  legalPersonScan(row) {
      this.checkData = row;
      this.showLegalPersonQRVisible = true; // Show the QR code dialog
      let jsonData = {
        id:row.id,
        type:26
      }
      this.legalPersonImg = await this.getCodeImage(jsonData);
    },



    /**
     * 获取验证码code
     * @param jsonData
     * @returns {Promise<unknown>}
     */
    async getCodeImage(jsonData){
      return new Promise(resolve => {
        getQRCodeImage(JSON.stringify(jsonData)).then(async (res)=>{
          if(res.code === 200){
            resolve("data:image/jpg;base64," + res.data.qrcode);
            await this.getScanData(this.checkData.id, res.data.ticket)
          }else{
            Message.error("二维码获取失败！")
          }
        })
      })
    },


    /** 下载模板操作 */
    importTemplate() {
      this.download('media/createWechatMp/importTemplate', {
      }, `user_template_${new Date().getTime()}.xlsx`)
    },


    /**
     * 获取手机验证码
     */
    getPhoneCacheCode(){
      getPhoneCacheCodeApi(this.ids).then((res)=>{
        console.log(res)
      })
    },

    sendPhoneCacheOne(row){
      Message.success("发送成功！")
      getPhoneCacheCodeApi(row.id).then((res)=>{
        console.log(res)
      })
    },

    /**
     * 提交管理员验证码
     */
    submitFormSystemPhoneCaptcha(){
      this.checkData.systemPhoneCaptcha =  this.form.systemPhoneCaptcha;
      updateCreateWechatMp(this.checkData).then(response => {
        console.log(response)
        this.closeModel()
        this.$modal.msgSuccess("验证码更新成功!");
        this.getList();
      });
    },

    /**
     * 关闭所有模态弹框
     */
    closeModel(){
      //法人扫码弹框
      this.showLegalPersonQRVisible = false
      //管理员扫码弹框
      this.systemScanVisible = false
      //管理员手机号验证
      this.systemPhoneCacheVisble = false
      this.scanTime = 300
      //关闭发送验证码禁用
      this.disableSendButton = false
      this.form = {}
    },





    /**
     * 获取二维码扫码状态
     */
   async getScanData(id, ticket){
      console.log(this.scanTime)
      if(this.scanTime < 1){
        return;
      }
      this.scanTime --;
      let jsonData ={
        id:id,
        ticket:ticket
      }
      setTimeout(()=>{
        getQRCodeRes(JSON.stringify(jsonData)).then((res)=>{
          if(res.code === 200){
            let resData = JSON.parse(res.msg);
            console.log(resData)
            if(resData.status === 1){
              this.scanTime = 0
              //修改法人扫码状态
              if(this.showLegalPersonQRVisible){
                this.updateLegalPersonScanStatus(id)
                //修改管理员扫码状态
              }else{
                this.updateSystemScanStatus(id)
              }
              this.closeModel();
            }else{
              this.getScanData(id, ticket);
            }
          }
        })
      },2000)
    },


    /**
     * 发送手机验证码
     */
    sendPhoneCache(){
      this.disableSendButton = true;
      getSystemPhoneCache(this.checkData.id).then((res)=>{
        if(res.code === 200){
          Message.success(res.msg)
        } else{
          Message.warning("发送失败，请重试！")
        }
      })
      setTimeout(() => {
      this.disableSendButton = false;
    }, 60000);
    },



    /**
     * 管理员扫码
     * @param row
     */
    async systemScan(row){
      this.checkData = row;
      this.systemScanVisible = true; // Show the QR code dialog
      let jsonData = {
        id:row.id,
        type:22
      }
      this.systemQRCodeImg = await this.getCodeImage(jsonData);
    },


    /** 查询快速创建公众号列表 */
    getList() {
      this.loading = true;
      listCreateWechatMp(this.queryParams).then(response => {
        this.createWechatMpList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },


    /**
     * 更新法人扫码状态
     * @param id
     */
    updateLegalPersonScanStatus(id){
      if(id){
        getCreateWechatMp(id).then(response => {
          response.data.legalPersonScanStatus = 1
          updateCreateWechatMp(response.data).then(response => {
            this.$modal.msgSuccess("状态已更新!");
            this.getList();
          })
        })
      }
    },

    /**
     * 更新管理员扫码状态
     * @param id
     */
    updateSystemScanStatus(id){
      if(id){
        getCreateWechatMp(id).then(response => {
          response.data.systemScanStatus = 1
          updateCreateWechatMp(response.data).then(response => {
            this.$modal.msgSuccess("状态已更新!");
            this.getList();
          })
        })
      }
    },

    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "公众号注册数据导入";
      this.upload.open = true;
    },


    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        deptId: undefined,
        userId: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        updateBy: undefined,
        username: undefined,
        password: undefined,
        accountType: undefined,
        enterpriseType: undefined,
        businessNumber: undefined,
        legalPersonName: undefined,
        legalPersonIdCard: undefined,
        systemName: undefined,
        systemIdCard: undefined,
        systemPhone: undefined,
        systemPhoneCaptcha: undefined,
        isSuccess: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },

    /**
     * 改变行样式
     * @param row
     * @param rowIndex
     */
    rowStyle({row, rowIndex}){
      if(row.cookies){
        return 'login_class'
      }else{
        return 'noLogin_class'
      }
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加公众号";
    },
    /**
     * 一键登录
     */
    handCreateMp(row){
      console.log(this.ids)
      if(this.ids.length < 1){
        Message.error("请选中行数据后登录！")
        return;
      }
      const id = row.id || this.ids
      createMp(id).then((res)=>{
        console.log(res)
      })
    },



    /**
     * 资料提交按钮
     * @param row
     */
    // handBatchSubmit(row){
    //   console.log(this.ids)
    //   if(this.ids.length < 1){
    //     Message.error("请选中行数据后登录！")
    //     return;
    //   }
    //   const id = row.id || this.ids
    //   batchCreateSubmit(id).then((res)=>{
    //     Message.success("执行成功!")
    //   })
    // },

    /**
     * 批量创建公众号
     * @param row
     */
    handBatchCreate(row){
      console.log(this.ids)
      if(this.ids.length < 1){
        Message.error("请选中行数据后登录！")
        return;
      }
      const id = row.id || this.ids
      batchCreateMp(id).then((res)=>{
        Message.success("执行成功!")
      })
    },


    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getCreateWechatMp(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改快速创建公众号";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateCreateWechatMp(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addCreateWechatMp(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除快速创建公众号编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delCreateWechatMp(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('media/createWechatMp/export', {
        ...this.queryParams
      }, `createWechatMp_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
.el-table .login_class {
  background: #ddf6dc;
}

.el-table .noLogin_class {
  background: #f3dddd;
}
</style>
